﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Hierarchy.Master" AutoEventWireup="true" CodeBehind="AreaMgrDetails.aspx.cs" Inherits="KPIBalanceScoreCard.AreaMgrDetails" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script type ="text/javascript" >
        function itemGroup(groupName) {
           // alert('hi');
            document.getElementById("ctl00_ContentPlaceHolder1_itemGroupName").value = groupName;
           // alert(document.getElementById("ctl00_ContentPlaceHolder1_itemGroupName").value);
            document.getElementById(groupName).style = "color: Green; font-weight:bolder"
        }
    
    </script>

<asp:HiddenField ID="itemGroupName" runat ="server" Value = "1.Business Target" EnableViewState="false"/>

    &nbsp;

    <table>
        <tr>
            <td>
            &nbsp;Year
                <asp:DropDownList ID="yearDropDown" runat="server" 
                    DataSourceID="YearDataSource" DataTextField="Year" DataValueField="Year" 
                    AutoPostBack="True" onselectedindexchanged="yearDropDown_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:SqlDataSource ID="YearDataSource" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:kpibalancescorecardConnectionString %>" 
                    SelectCommand="SELECT DISTINCT [Year] FROM [Balance] order by year desc"></asp:SqlDataSource>
            </td>
            <td>
            &nbsp;Month
                <asp:DropDownList ID="monthDropDown" runat="server" 
                    DataSourceID="MonthDataSource" DataTextField="Month" 
                    DataValueField="Month" AutoPostBack="True" 
                    onselectedindexchanged="monthDropDown_SelectedIndexChanged">
                </asp:DropDownList>
                <asp:SqlDataSource ID="MonthDataSource" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:kpibalancescorecardConnectionString %>" 
                    SelectCommand="SELECT DISTINCT Month FROM Balance ORDER BY Month DESC"></asp:SqlDataSource>
            </td>
        </tr>
    </table>
    
    <br />
    <hr /><hr />

<table>
<!-- 
    <tr>
        <th>
            Branch
        </th>
        <td>
            <asp:RadioButtonList ID="rdbBranch" runat="server" AutoPostBack="True" 
                DataSourceID="BranchDataSource" DataTextField="OrganizationName" 
                DataValueField="OrganizationName" RepeatDirection="Horizontal" 
                RepeatColumns="10">
            </asp:RadioButtonList>
            <asp:SqlDataSource ID="BranchDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:kpibalancescorecardConnectionString %>" 
                SelectCommand="SELECT distinct OrganizationName FROM Balance WHERE (OrganizationParentName IN (SELECT Balance.OrganizationParentName FROM Balance WHERE (Balance.EmployeeUserRef = @empId)))">
                <SelectParameters>
                    <asp:SessionParameter DefaultValue=" " Name="empId" SessionField="LOGIN_PK" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
      </tr>

-->
      <tr>   
        <th>
            Roles
        </th>
        <td>
            <asp:RadioButtonList ID="rdbRole" runat="server" DataSourceID="RoleDataSource" 
                DataTextField="RoleName" DataValueField="RoleName" AutoPostBack="True" 
                RepeatColumns="10" RepeatDirection="Horizontal" 
                onselectedindexchanged="rdbRole_SelectedIndexChanged">
            </asp:RadioButtonList>
            <asp:SqlDataSource ID="RoleDataSource" runat="server" 
                ConnectionString="<%$ ConnectionStrings:kpibalancescorecardConnectionString %>" 
                
                SelectCommand="SELECT distinct RoleName FROM Balance WHERE (OrganizationParentName IN (SELECT Balance.OrganizationParentName FROM Balance WHERE (Balance.EmployeeUserRef = @empId)))">
                <SelectParameters>
                    <asp:SessionParameter DefaultValue="-1" Name="empId" SessionField="LOGIN_PK" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
</table>

    
    
<% if (Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_GROUPS.ToString()] != null)
   {%>
    <table>
        <tr>
            <th> <i>Score Card</i>&nbsp;</th>
            <%
    KPIBalanceScoreCard.HierarchyDataset.ItemGroupsDataTable itemGroupDt = new KPIBalanceScoreCard.HierarchyDataset.ItemGroupsDataTable();


    itemGroupDt = (KPIBalanceScoreCard.HierarchyDataset.ItemGroupsDataTable)Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_GROUPS.ToString()];

    foreach (KPIBalanceScoreCard.HierarchyDataset.ItemGroupsRow itemGroupDr in itemGroupDt.Rows)
    {%>
            <th>               
               <input style="width:150px; font-size:medium" id="<%= itemGroupDr.ItemGroup %>" type="submit" onclick = "itemGroup('<%= itemGroupDr.ItemGroup %>');" value = "<%= itemGroupDr.ItemGroup %>" />               
            </th>  
            <% 
    }
   
                 %>         
        </tr>
    </table>
   <%} %> 
    <br /><hr /><br />
   
    
    
    <%if(Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()]!= null && !"".Equals(Session[KPIBalanceScoreCard.ApplicationConstants.SELECTED_ITEM_GROUP.ToString()].ToString())) { %>
        
     <table>
        <tr>
            <th>
             <%=itemGroupName.Value %> Score Card
            </th>
        </tr>        
    </table>
    <hr />
   
    
    <table>
        <tr>
        <td valign="top">
        <table>
            <tr>               
                <th>
                MTD
                </th>
            </tr>
        </table>
        <table border="1">
            <tr>
            <th>Item Name</th>
            <th>Actual</th>
            <th>Target</th>
            <th>%</th>
            <th>Weight</th>
            <th>Score</th>
            </tr>
            <%if (Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_MTD.ToString()] != null)
              {
                  KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable detailsDtMTD = (KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable)Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_MTD.ToString()];

                  foreach (KPIBalanceScoreCard.HierarchyDataset.ItemDetailsRow detailsRow in detailsDtMTD.Rows)
                  {                
                  %>
            <tr>
                <td nowrap="nowrap"><%= detailsRow.ItemName %></td>
                <td><%= detailsRow.actual %></td>
                <td><%= detailsRow.budget %></td>
                <% double actual = double.Parse(detailsRow.actual.ToString());
                   double budget = double.Parse(detailsRow.budget.ToString());
                   if (budget == 0)
                   {
                       budget = actual;
                   }  
                      
                    double result = (actual / budget) * 100;
                    result = Math.Round(result, 2);
                %>
                
                <td style ="color:<%= result < 80 ? "White" : result > 80 && result < 89.99 ? "Black" : result > 90 && result < 95.99 ? "White" : "White"%>; background-color:<%= result < 80 ? "Red" : result > 80 && result < 89.99 ? "YELLOW" : result > 90 && result < 95.99 ? "GREEN" : "BLUE"%>"><%=  actual == 0 ? 00.00 : result%></td>
                <td><%= detailsRow.weight %></td>
                <td><%= detailsRow.score %></td>        
            </tr>
            <%}
              } %>
        </table>
   </td>
   <td valign="top">
        <table>
            <tr>
                <th>
                &nbsp;YTD
                </th>
            </tr>
            
        </table>
    
        <table border="1">
            <tr>
           <!--  <th>Item Name</th> -->
            <th>Actual</th>
            <th>Target</th>
            <th>%</th>
            <th>Weight</th>
            <th>Score</th>
            </tr>
            <%if (Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_YTD.ToString()] != null)
              {
                  KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable detailsDtYTD = (KPIBalanceScoreCard.HierarchyDataset.ItemDetailsDataTable)Session[KPIBalanceScoreCard.ApplicationConstants.ITEM_DETAILS_YTD.ToString()];
                  foreach (KPIBalanceScoreCard.HierarchyDataset.ItemDetailsRow detailsRow in detailsDtYTD.Rows)
                  {                
                  %>
            <tr>
                <!-- <td><%= detailsRow.ItemName %></td> -->
                <td><%= detailsRow.actual %></td>
                <td><%= detailsRow.budget %></td>
                <% double actual = double.Parse(detailsRow.actual.ToString());
                   double budget = double.Parse(detailsRow.budget.ToString());
                   if (budget == 0)
                   {
                       budget = actual;
                   }
                   double result = Math.Round((actual / budget) * 100, 2);
                %>
                
                <td style ="color:<%= result < 80 ? "White" : result > 80 && result < 89.99 ? "Black" : result > 90 && result < 95.99 ? "White" : "White"%>; background-color:<%= result < 80 ? "Red" : result > 80 && result < 89.99 ? "YELLOW" : result > 90 && result < 95.99 ? "GREEN" : "BLUE"%>"><%= actual == 0 ? 00.00 : result%></td>
                <td><%= detailsRow.weight %></td>
                <td><%= detailsRow.score %></td>        
            </tr>
            <%}
            } %>
        </table>
    </td>
    </tr>
    </table>    
    
    <%} %>


</asp:Content>
